/********************************************/
  // Creation History
  // --------------------------------------------------------------
  //	Company:			HTHK
  //	NAME:				CompanyServlet.java
  //    Title   :			operate A Company Record such as:Create,Update,Delete
  //	FUNCTION:
  //	BY:					Jet Tao
  //	DATE:				09/12/2003
  // --------------------------------------------------------------
/*********************************************/

package tss.company;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.log4j.Logger;

import java.io.*;
import java.sql.*;

import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;
import com.ffpc.util.*;

import tss.common.DBServlet2;


public class CompanyServlet
  extends DBServlet2 {
	private Logger logger = Logger.getLogger(CompanyServlet.class);
  @Override
protected String perform(  HttpServletRequest request,
                             HttpServletResponse response,
                             StrutsMessage message)
    throws  ServletException,
            IOException,
            SQLException,
            DataException,
            Exception
  {
     //New A Form Action
     String action = new String(request.getParameter("formAction"));
     //New A Company Record
     CompanyBean Company=CompanyProcess.createBean();

     //Get A Company Record
     Company.setCompany_code(request.getParameter("company_code"));
     Company.setCompany_name(request.getParameter("company_name"));

     //Deal different operations
     //Insert
      if (action.trim().equalsIgnoreCase("Create"))
      {
        //Set Company's Create Date and Create By
        Company.setCreate_date(DateFormatter.format(this.getDate()));
        Company.setCreate_by(getUser().getUser_name());
        if (CompanyProcess.insert(this.getConnection(),Company)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure");
      }
      //Update
      else if (action.trim().equalsIgnoreCase("Update"))
      {
        //Set Company's Update Date and Update By
        Company.setUpd_date(DateFormatter.format(this.getDate()));
        Company.setUpd_by(getUser().getUser_name());
        logger.debug("Update by "+getUser().getUser_name());
        if (CompanyProcess.update(this.getConnection(), Company) > 0)
          message.setMessage("Save successfully.");
        else
          message.setMessage("Save failure.");
      }
      //Delete
      else if (action.trim().equalsIgnoreCase("Delete"))
        if (CompanyProcess.delete(this.getConnection(),Company)>0)
            message.setMessage("Delete successfully.");
        else
            message.setMessage("Delete failure.");
      else
            message.setMessage("No action mapped!");

      return "tss/company/CompanySearch.jsp";
  }
}


